/**
 * @author GhostWei
 */
var hihicar = {
	switchDrag: false,	
	bindSwitch: function() {
		$('#switch').mousedown(function(e){
			hihicar.switchDrag = true;
			$('body').css('cursor','e-resize');		
			$(document).mousemove(function(e){
				if(!hihicar.switchDrag) return;
				var x = e.clientX;
				var t = $('#header').height() + 3;		
				$('#tree').css({"width" : x + 'px'});
				if($.browser.msie) $('#maskDiv').css({'display': 'block', 'filter': 'alpha(opacity:0)'});
				hihicar.resize();
				$('#switch').css({'left': x+'px', 'top': t+'px'});		
			}).mouseup(function(e){
				if(!hihicar.switchDrag) return;
				hihicar.switchDrag = false;
				$('body').css('cursor','default');
				if($.browser.msie) $('#maskDiv').css('display','none');
				hihicar.resize();
			});
		});
	},	
	resize: function() {
		var sourceHeight = $('#header').height() + 3;
		var bodyWidth = $('#body').width();
		var treeWidth = $('#tree').width();
		var switchWidth = $('#switch').width();
		var bodyHeight = $(window).height();
		
		var mainHeight = parseInt(bodyHeight - sourceHeight) + 'px';
			
		$('#tree').css({"height" : mainHeight});
		$('#switch').css({"height" : mainHeight, 'left': treeWidth + 'px', 'top': sourceHeight + 'px'});		
		$('#frame').css({
			"width" : parseInt(bodyWidth - (treeWidth + switchWidth)) + 'px',
			"height" : mainHeight
		});
		if($.browser.msie) {
			$('#maskDiv').css({
				'left': (treeWidth + switchWidth) + 'px', 
				'top': 0 + 'px', 
				'width': parseInt(bodyWidth - (treeWidth + switchWidth)) + 'px', 
				'height': mainHeight
			});
		}
		$('#mainFrame').css({
			"width" : "100%",
			"height" : mainHeight,
			"overflow-x" : "hidden"
		});
		if($.browser.msie){
			$('#mainFrame').css({
				'overflow-y' : 'auto'
			});
		}
	}
};
$(window).resize(function(){hihicar.resize();});
$(document).ready(function(){hihicar.bindSwitch();hihicar.resize();});
